﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Areas.AdminCP.Models;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class AdminDestinationInfoController : Controller
    {
        //
        // GET: /AdminCP/AdminDestinationInfo/

        public ActionResult Index()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = from p in db.EntityDestinationInfos
                            select new AdminDestinationInfoModel
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description
                            };
                return View(query.FirstOrDefault());
            }
        }

        public ActionResult Edit(int id)
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = from p in db.EntityDestinationInfos
                            where p.Id == id
                            select new AdminDestinationInfoModel
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                Meta_description = p.Meta_description,
                                Meta_keyword = p.Meta_keyword,
                                Titletag = p.Titletag
                            };
                return View(query.FirstOrDefault());
            }
        }


        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(AdminDestinationInfoModel model)
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                EntityDestinationInfo Info = db.EntityDestinationInfos.FirstOrDefault(p => p.Id == model.Id);
                if (Info != null)
                {
                    Info.Name = model.Name;
                    Info.Description = model.Description;
                    Info.Meta_keyword = model.Meta_keyword;
                    Info.Meta_description = model.Meta_description;
                    Info.Titletag = model.Titletag;
                    db.SubmitChanges();
                    return RedirectToAction("Index");
                }
                else
                    return View("Error");
            }
        }

    }
}
